package com.example.suspensionbardemo.adapter;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import androidx.viewpager2.adapter.FragmentStateAdapter;

import java.util.List;

/**
 * 创建日期：2022/1/4  14:53
 * 描述：FragmentStateAdapter   FragmentPagerAdapter  FragmentStatePagerAdapter
 * <p>
 * vierpager2+FragmentStateAdapter 自带懒加载功能，
 */
public class ViewPager2Adapter extends FragmentStateAdapter {

    private List<Fragment> data;

    public ViewPager2Adapter(@NonNull FragmentActivity fragmentActivity, List<Fragment> data) {
        super(fragmentActivity);
        this.data = data;
    }

    @NonNull
    @Override
    public Fragment createFragment(int position) {
        return data.get(position);
    }

    @Override
    public int getItemCount() {
        return data.size();
    }
}
